<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">注册</view>
			<input class="u-border-bottom" v-model="username" placeholder="请输入用户名" required/>
			<input class="u-border-bottom" v-model="phone" placeholder="请输入手机号" required/>
			<input class="u-border-bottom" v-model="email" placeholder="请输入邮箱"  type="email" required/>
			<input class="u-border-bottom" type="possword" v-model="password" placeholder="请输入密码" required/>
			<input class="u-border-bottom" type="possword" v-model="password2" placeholder="确认密码" required/>
			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">注册</button>
			<view class="alternative">
				<view class="password" @click="zc">登录</view>
				<view class="issue">遇到问题</view>
			</view>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs,computed } from 'vue'
import {userRegisterApi} from '../../https/http'

const data = reactive<API.userRegisterData>({
	username: '',
	phone: '',
	email: '',
	password: '',
	password2: '',
	sex:2,
	age:18,
	avatar:"",
	sign:"",
	info:"",

})
const inputStyle = computed(() => {
		let style:{
      color?:string
      backgroundColor?:string
    } = {};
		if (!(data.username && data.password)) {
			style.color = "#fff";
			style.backgroundColor = "rgb(253, 243, 208)";
		}
		return style;
})
const submit = async() => {
    if (data.username && data.password) {
		const res = await userRegisterApi(data)
		if(res.code == 200){
			uni.redirectTo({
				url: '/pages/login/login'
			})
		}
	}
}
const zc = () => {
    uni.redirectTo({
		url: '/pages/login/login'
	})
}
const {username,email,phone,password,password2} = toRefs(data)
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 80rpx auto 0;

			.title {
				text-align: left;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.getCaptcha {
				background-color: rgb(253, 243, 208);
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}
	}
</style>
